package cn.explink.dop.entity.vo;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonIgnore;

import cn.explink.dop.enums.pub.EnableEnum;
import cn.explink.eap.core.common.entity.IdEntity;

/**
 * 基本信息实体
 *
 * @author firefly 2015-2-5 12:48
 *
 */
@Entity
@Table(name = "bd_area", schema = "")
public class AreaVO extends IdEntity implements java.io.Serializable {
	private static final long serialVersionUID = -9019979740251029515L;

	/** 区域名称 */
	private String baseAreaName;
	/** 坐标 */
	private String baseCoordinate;
	/** 是否启用， 1：启用；2：禁用 */
	private int baseEnable;
	/** 是否删除， 1：正常；2：删除 */
	private int baseDelete;
	/** 添加时间 */
	private String createDate;
	/** 修改时间 */
	private String updateDate;
	/** 创建人 */
	private String createUser;
	/** 修改人 */
	private String updateUser;

	/** 创建人姓名 */
	private String createUserName;
	/** 修改人姓名 */
	private String updateUserName;
	/** 中心点经度 **/
	private BigDecimal mapcenterLng;
	/** 中心点纬度 **/
	private BigDecimal mapcenterLat;
	/**
	 * 区域uid
	 */
	private String uid;

	/**
	 * 配送员
	 */
	private List<DeliveryManVO> deliveryManList;

	private List<StorefrontVO> storefrontList;

	// @Column(name = "base_area_name", nullable = true, length = 200)
	@Column(name = "base_area_name", nullable = true, columnDefinition = "longtext")
	public String getBaseAreaName() {
		return this.baseAreaName;
	}

	public void setBaseAreaName(String baseAreaName) {
		this.baseAreaName = baseAreaName;
	}

	@Column(name = "base_coordinate", nullable = true, length = 60000)
	public String getBaseCoordinate() {
		return this.baseCoordinate;
	}

	public void setBaseCoordinate(String baseCoordinate) {
		this.baseCoordinate = baseCoordinate;
	}

	@Column(name = "base_enable", nullable = true, length = 2)
	public int getBaseEnable() {
		return this.baseEnable;
	}

	public void setBaseEnable(int baseEnable) {
		this.baseEnable = baseEnable;
	}
	
	@Transient
	public String getBaseEnableText() {
		if(EnableEnum.Enable.getValue()==this.baseEnable){
			return EnableEnum.Enable.getText();
		}
		return EnableEnum.Unable.getText();
	}

	@Column(name = "base_delete", nullable = true, length = 2)
	public int getBaseDelete() {
		return this.baseDelete;
	}

	public void setBaseDelete(int baseDelete) {
		this.baseDelete = baseDelete;
	}

	@Column(name = "create_date", nullable = true, length = 23)
	public String getCreateDate() {
		return this.createDate;
	}

	public void setCreateDate(String createDate) {
		this.createDate = createDate;
	}

	@Column(name = "update_date", nullable = true, length = 23)
	public String getUpdateDate() {
		return this.updateDate;
	}

	public void setUpdateDate(String updateDate) {
		this.updateDate = updateDate;
	}

	@Column(name = "create_user", nullable = true, length = 32)
	public String getCreateUser() {
		return this.createUser;
	}

	public void setCreateUser(String createUser) {
		this.createUser = createUser;
	}

	@Column(name = "update_user", nullable = true, length = 32)
	public String getUpdateUser() {
		return this.updateUser;
	}

	public void setUpdateUser(String updateUser) {
		this.updateUser = updateUser;
	}

	@Transient
	public String getCreateUserName() {
		return this.createUserName;
	}

	public void setCreateUserName(String createUserName) {
		this.createUserName = createUserName;
	}

	@Transient
	public String getUpdateUserName() {
		return this.updateUserName;
	}

	public void setUpdateUserName(String updateUserName) {
		this.updateUserName = updateUserName;
	}

	@Column(name = "mapcenter_lng", nullable = true, length = 50)
	public BigDecimal getMapcenterLng() {
		return this.mapcenterLng;
	}

	public void setMapcenterLng(BigDecimal mapcenterLng) {
		this.mapcenterLng = mapcenterLng;
	}

	@Column(name = "mapcenter_lat", nullable = true, length = 50)
	public BigDecimal getMapcenterLat() {
		return this.mapcenterLat;
	}

	public void setMapcenterLat(BigDecimal mapcenterLat) {
		this.mapcenterLat = mapcenterLat;
	}

	public String getUid() {
		return this.uid;
	}

	public void setUid(String uid) {
		this.uid = uid;
	}

	@JsonIgnore
	@ManyToMany(targetEntity = DeliveryManVO.class, cascade = CascadeType.ALL)
	@JoinTable(name = "bd_area_deliveryman", joinColumns = @JoinColumn(name = "area_id"), inverseJoinColumns = @JoinColumn(name = "deliveryman_id"))
	public List<DeliveryManVO> getDeliveryManList() {
		return this.deliveryManList;
	}

	public void setDeliveryManList(List<DeliveryManVO> deliveryManList) {
		this.deliveryManList = deliveryManList;
	}

	@Transient
	public List<String> getDeliveryManIdList() {
		List<String> deliveryManIdList = new ArrayList<String>();
		if ((this.deliveryManList != null) && (this.deliveryManList.size() > 0)) {
			for (DeliveryManVO deliveryManVO : this.deliveryManList) {
				deliveryManIdList.add(deliveryManVO.getId());
			}
		}
		return deliveryManIdList;
	}

	@Transient
	public String getDeliverymanName() {
		String deliverymanName = "";
		if ((this.deliveryManList != null) && (this.deliveryManList.size() > 0)) {
			for (DeliveryManVO deliveryManVO : this.deliveryManList) {
				deliverymanName += " " + deliveryManVO.getDelName();
			}
		}
		return deliverymanName;
	}

	@JsonIgnore
	@ManyToMany(targetEntity = StorefrontVO.class, cascade = CascadeType.ALL)
	@JoinTable(name = "bd_storefront_area", joinColumns = @JoinColumn(name = "area_id"), inverseJoinColumns = @JoinColumn(name = "storefront_id"))
	public List<StorefrontVO> getStorefrontList() {
		return this.storefrontList;
	}

	public void setStorefrontList(List<StorefrontVO> storefrontList) {
		this.storefrontList = storefrontList;
	}

	@Transient
	public String getStorefrontId() {
		String storefrontId = "";
		if ((this.storefrontList != null) && (this.storefrontList.size() > 0)) {
			for (StorefrontVO storefrontVO : this.storefrontList) {
				storefrontId += storefrontVO.getId();
			}
		}
		return storefrontId;
	}

	@Transient
	public List<String> getStorefrontIdList() {
		List<String> storefrontIdList = new ArrayList<String>();
		if ((this.storefrontList != null) && (this.storefrontList.size() > 0)) {
			for (StorefrontVO storefrontVO : this.storefrontList) {
				storefrontIdList.add(storefrontVO.getId());
			}
		}
		return storefrontIdList;
	}

	@Transient
	public String getStorefrontName() {
		String storefrontName = "";
		if ((this.storefrontList != null) && (this.storefrontList.size() > 0)) {
			for (StorefrontVO storefrontVO : this.storefrontList) {
				storefrontName += " " + storefrontVO.getStoName();
			}
		}
		return storefrontName;
	}

}
